//
//  MJHeightPiker.m
//  module_more
//
//  Created by HappyMilk 02 on 2017/2/10.
//  Copyright © 2017年 HappyMilk 02. All rights reserved.
//

#import "MJHeightPiker.h"

@interface MJHeightPiker ()<UIPickerViewDelegate,UIPickerViewDataSource>

@property (weak, nonatomic) IBOutlet UIPickerView *pikerview;

@property (nonatomic, strong) UIView *zhedangView;
@property (nonatomic, strong) NSString *ren_height;

@end

@implementation MJHeightPiker

- (void)tap:(UIGestureRecognizer *)tap{
    self.chioceHeight(_ren_height);
    [self removeFromSuperview];
    [_zhedangView removeFromSuperview];
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self = [[[NSBundle mainBundle] loadNibNamed:@"MJHeightPiker" owner:nil options:nil] lastObject];
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 5;
        _ren_height = @"140";
        
        _pikerview.showsSelectionIndicator = YES;
        _pikerview.delegate = self;
        _pikerview.dataSource = self;
        
        
    }
    return self;
}

- (void)showHeightPikerViewInView:(UIView*)rootView{

    self.zhedangView = [[UIView alloc] initWithFrame:rootView.frame];
    self.zhedangView.backgroundColor = [UIColor blackColor];
    self.zhedangView.alpha = 0.4;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    [self.zhedangView addGestureRecognizer:tap];
    
    [rootView addSubview:self.zhedangView];
    [rootView addSubview:self];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 2;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    switch (component) {
        case 0:
            return 60;
            break;
            
        default:
            return 1;
            break;
    }
    return 20;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (component == 0) {
        NSInteger a = 140;
        NSString *str = [NSString stringWithFormat:@"%ld",a+row];
        return str;
    }else{
        return @"Cm";
    }
    
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    NSInteger a = 140;
    NSString *str = [NSString stringWithFormat:@"%ld",a+row];
    _ren_height = str;
}


@end
